<template>
  <div>
    <el-row :gutter="10" style="margin-bottom: 40px">
      <el-col :span="6">
        <el-card>
          <div style="color: #409EFF">👨‍💼管理员总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ users }}
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card>
          <div style="color: #409EFF">👨‍🦽病人总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ patients }}
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card>
          <div style="color: #409EFF">🏥科室总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ sectors }}
          </div>
        </el-card>
      </el-col>

      <el-col :span="6">
        <el-card>
          <div style="color: #409EFF">🏢病房总数</div>
          <div style="padding: 10px 0; text-align: center; font-weight: bold">
            {{ rooms }}
          </div>
        </el-card>
      </el-col>
    </el-row>

    <el-row>
      <el-col :span="12">
        <div id="main" style="width: 500px;height: 450px;"></div>
      </el-col>

      <el-col :span="12">
        <div id="pie" style="width: 500px;height: 450px;"></div>
      </el-col>
    </el-row>

  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  name: "Home",
  data() {
    return{
      users: 0,
      patients: 0,
      sectors: 0,
      rooms: 0
    }
  },
  created() {
    setTimeout( () => {
      if(JSON.parse(localStorage.getItem("user")).avatarUrl === null) {
        this.$message.warning("还没头像，请先去上传头像")
      }
    }, 1500)
    // 获取管理员总数
    this.request.get("/echarts/users").then( res => {
        this.users = res.data
    })

    // 获取病人总数
    this.request.get("/echarts/patients").then( res => {
      this.patients = res.data
    })

    // 获取科室总数
    this.request.get("/echarts/sectors").then( res => {
      this.sectors = res.data
    })

    // 获取病房总数
    this.request.get("/echarts/rooms").then( res => {
      this.rooms = res.data
    })
  },
  // 页面渲染之后在触发
  mounted() {
    // 折线柱状图
    var chartDom = document.getElementById('main');
    var myChart = echarts.init(chartDom);
    var option = {
      title: {
        text: '医生职位人数的统计',
        subtext: '趋势图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      xAxis: {
        type: 'category',
        data: ['主治医师', '副主治医师', '主任医师', '副主任医师', '住院医师']
      },
      yAxis: {
        type: 'value'
      },
      series: [
        {
          data: [],
          type: 'line'
        },
        {
          data: [],
          type: 'bar'
        }
      ]
    };

    // 饼状图
    var pieDom = document.getElementById('pie');
    var pieChart = echarts.init(pieDom);
    var pieOption = {
      title: {
        text: '医生职位人数的统计',
        subtext: '饼状图',
        left: 'center'
      },
      tooltip: {
        trigger: 'item'
      },
      legend: {
        orient: 'vertical',
        left: 'left'
      },
      series: [
        {
          type: 'pie',
          radius: '60%',
          label:{            //饼图图形上的文本标签
            normal:{
              show:true,
              position:'inner', //标签的位置
              textStyle : {
                fontWeight : 300 ,
                fontSize : 14,    //文字的字体大小
                color: "#fff"
              },
              formatter:'{d}%'
            }
          },
          data: [],
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          }
        }
      ]
    };



    this.request.get("/echarts/doctor").then(res => {
      option.series[0].data = res.data
      option.series[1].data = res.data
      myChart.setOption(option);


      pieOption.series[0].data = [
        { value: res.data[0], name: '主治医师' },
        { value: res.data[1], name: '副主治医师' },
        { value: res.data[2], name: '主任医师' },
        { value: res.data[3], name: '副主任医师' },
        { value: res.data[4], name: '住院医师' }
      ]
      pieChart.setOption(pieOption);
    })



  }
}
</script>

<style scoped>

</style>